import {httpAction} from "@api/manage";

export const DrawerFormMixin = {
    data() {
        return {
            title:"操作",
            drawerWidth:700,
            visible: false,
            model: {},
            confirmLoading: false,
            disableSubmit:false,
            dateFormat:"YYYY-MM-DD",
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
        }
    },
    methods: {
        handleSubmit(){
            let that = this;
            that.$refs['formRef'].validate(valid => {
                if(valid){
                    let url = that.url.add;
                    let method = 'post';
                    if (that.model.id) {
                        url = that.url.edit
                        method = 'put'
                    }
                    console.info("this.model",that.model);
                    console.info("url",url);
                    console.info("method",method);
                    this.confirmLoading = true;
                    httpAction(url, that.model, method).then((res) => {
                        if(res.success){
                            that.$message.success(res.message);
                            that.$emit("ok");
                            that.handleCancel();
                        }else {
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    });
                }
            })
        },

        handleCancel(){
            this.visible=false;
        }
    }
}